package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class GenericDaoImpl implements GenericDao {
	private static Connection con;

	public Connection getConnection() {

		try {
			Class.forName("net.sourceforge.jtds.jdbc.Driver");

			StringBuffer sb = new StringBuffer();
			sb.append("jdbc:jtds:sqlserver://");
			sb.append("127.0.0.1");
			sb.append(":1433;DatabaseName=glossariocomex");
			String id = "sa";
			String p =  "1234";
//			String id = "l.colevati";
//			String p =  "com@fatec";
			con = DriverManager
					.getConnection(
							sb.toString(),
							id,p);
//			System.out.println("Conexao ok");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;
	}
	
	public Connection getConnectionMaster() {

		try {
			Class.forName("net.sourceforge.jtds.jdbc.Driver");
			con = DriverManager
					.getConnection(
							"jdbc:jtds:sqlserver://127.0.0.1:1433;DatabaseName=master;namedPipe=true",
							"l.colevati", "com@fatec");
//			System.out.println("Conexao ok");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;
	}

	public void fechaConexao() {
		try {
			if (con != null)
				con.close();
			con = null;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}